var hl_comm = new Object();

import WUtil from './util.js'


let thisCurrentLanguage=localStorage.getItem('currentLanguage');


export default {
	//数字校验(小数,0,负数都可以)
	validateNum: function (rule,value,callback){
        if(!value){
            return callback();
        }
        setTimeout(() => {
            var  regUrl = /^(-?\d+)(\.\d+)?$/;
            if(!regUrl.test(value)){
				if(thisCurrentLanguage=='zh'){
					callback(new Error('请输入数字'));
				}else if(thisCurrentLanguage=='en'){
					callback(new Error('Please enter the number'));
				}else if(thisCurrentLanguage=='it'){
					callback(new Error('Si prega di inserire un numero'));
				}
                
            }else{
                callback();
            }
        },100);
    },
    //自然数校验(大于等于0)
    validateNaturalNumber: function (rule,value,callback){
    	if(!value){
			return callback();
		};
    	setTimeout(() => {
			var  regUrl = /^[0-9]*$/;
			if(!regUrl.test(value)){
				if(thisCurrentLanguage=='zh'){
					callback(new Error('请输入自然数'));
				}else if(thisCurrentLanguage=='en'){
					callback(new Error('Please enter a natural number'));
				}else if(thisCurrentLanguage=='it'){
					callback(new Error('Si prega di inserire un numero naturale'));
				}
				
			}else{
				callback();
			}
		},100);
    },
    //正整数校验(不能为0)
    validatePositiveInteger: function (rule,value,callback){
    	if (!value) {
        	return callback();
      	};
      	setTimeout(() => {
      		var regUrl=/^[0-9]*[1-9][0-9]*$/;
          	if (!regUrl.test(value)) {
				if(thisCurrentLanguage=='zh'){
					callback(new Error('请输入正整数'));
				}else if(thisCurrentLanguage=='en'){
					callback(new Error('Please enter a positive integer'));
				}else if(thisCurrentLanguage=='it'){
					callback(new Error('Per favore inserisci un numero intero positivo'));
				}
            	
          	}else{
              	callback();
          	}
      	}, 100);
    },
    //手机号校验
    validatePhoneNumber: function (rule,value,callback){
    	if(!value){
			if(thisCurrentLanguage=='zh'){
				return callback(new Error('手机号码不能为空'));
			}else if(thisCurrentLanguage=='en'){
				return callback(new Error('Phone number can not be blank'));
			}else if(thisCurrentLanguage=='it'){
				return callback(new Error('Il numero di cellulare non può essere vuoto'));
			}
			
		};
		setTimeout(() => {
			var  regUrl = /^1(3|4|5|7|8)\d{9}$/;
			if(!regUrl.test(value)){
				if(thisCurrentLanguage=='zh'){
					callback(new Error('手机号码格式不正确'));
				}else if(thisCurrentLanguage=='en'){
					callback(new Error('Phone number format is incorrect'));
				}else if(thisCurrentLanguage=='it'){
					callback(new Error('Il formato del numero di telefono non è corretto'));
				}
				
			}else{
				callback();
			}
		},100);
    },
    //网址校验
    validateUrl: function (rule,value,callback){
    	if(WUtil.vad.isBlank(value)) {
			if(thisCurrentLanguage=='zh'){
				callback(new Error('请输入链接地址'));
			}else if(thisCurrentLanguage=='en'){
				callback(new Error('Please enter the link address'));
			}else if(thisCurrentLanguage=='it'){
				callback(new Error("Si prega di inserire l'indirizzo del link"));
			}
			
		};
		setTimeout(() => {
			var regUrl = /^(https?|ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)*(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/;
			if(!regUrl.test(value)){
				if(thisCurrentLanguage=='zh'){
					callback(new Error('网址格式不正确,例：http://www.xxxx.com'));
				}else if(thisCurrentLanguage=='en'){
					callback(new Error('The URL format is incorrect, for example: http://www.xxxx.com'));
				}else if(thisCurrentLanguage=='it'){
					callback(new Error("Il formato dell'URL non è corretto, ad esempio: http://www.xxxx.com"));
				}
				
			} else {
				callback();
			}
		}, 200);
    },
    //电话校验
    validateTelephone: function (rule,value,callback){
    	if(WUtil.vad.isBlank(value)) {
			callback();
		};
		setTimeout(() => {
			var regPhone = /^0\d{2,3}-?\d{7,8}$/;
			if(!regPhone.test(value)){
				if(thisCurrentLanguage=='zh'){
					callback(new Error('请输入正确的电话号码'));
				}else if(thisCurrentLanguage=='en'){
					callback(new Error('Please enter the correct phone number'));
				}else if(thisCurrentLanguage=='it'){
					callback(new Error('Si prega di inserire il numero di telefono corretto'));
				}
				
			}else {
				callback();
			}
		}, 200);
    },
    //电话或手机校验
    validateTelephoneNumber: function (rule,value,callback){
    	if(WUtil.vad.isBlank(value)) {
			callback();
		};
		setTimeout(() => {
			var regPhone = /(^(\(\d{3,4}\)|\d{3,4}-|\s)?\d{7,14}?$)|(^((\(\d{3}\))|(\d{3}\-))?(1[34578]\d{9})$)/;
			if(!regPhone.test(value)){
				if(thisCurrentLanguage=='zh'){
					callback(new Error('请输入正确的联系方式'));
				}else if(thisCurrentLanguage=='en'){
					callback(new Error('Please enter the correct contact method'));
				}else if(thisCurrentLanguage=='it'){
					callback(new Error('Si prega di inserire il metodo di contatto corretto'));
				}
				
			}else {
				callback();
			}
		}, 200);
    },
    //验证登录名用户名正则，4到16位（字母，数字，下划线，减号）
    validateLoginName: function (rule,value,callback){
    	if (!value) {
        	return callback();
      	}
    	setTimeout(() => {
        	var containSpecial = RegExp(/^[a-zA-Z0-9_-]{4,16}$/); 
          	if (!containSpecial.test(value)) {
				if(thisCurrentLanguage=='zh'){
					callback(new Error('用户名规则:4到16位(字母，数字，下划线，减号)'));
				}else if(thisCurrentLanguage=='en'){
					callback(new Error('Username rules: 4 to 16 digits (letters, numbers, underscores, minus signs)'));
				}else if(thisCurrentLanguage=='it'){
					callback(new Error('Regole del nome utente: da 4 a 16 cifre (lettere, numeri, underscore, segni meno)'));
				}
            	
          	}else{
              	callback();
          	}
      	}, 200);
    },
    //密码强度正则，最少6位，包括至少1个大写字母，1个小写字母，1个数字，1个特殊字符
    validateLoginPassword: function (rule,value,callback){
    	if (!value) {
        	return callback();
      	}
    	setTimeout(() => {
        	var containSpecial = RegExp(/^.*(?=.{6,})(?=.*\d)(?=.*[A-Z])(?=.*[a-z])(?=.*[!@#$%^&*? ]).*$/); 
          	if (!containSpecial.test(value)) {
				  if(thisCurrentLanguage=='zh'){
					  callback(new Error('密码规则:最少6位,包括至少大写字母、小写字母、数字、特殊字符'));
				  }else if(thisCurrentLanguage=='en'){
					  callback(new Error('Password rules: a minimum of 6 digits, including at least uppercase letters, lowercase letters, numbers, special characters'));
				  }else if(thisCurrentLanguage=='it'){
					  callback(new Error('Regole della password: un minimo di 6 cifre, tra cui almeno lettere maiuscole, lettere minuscole, numeri, caratteri speciali'));
				  }
            	
          	}else{
              	callback();
          	}
      	}, 200);
    },    
    //特殊符号校验
    validateSpecialCharacters: function (rule,value,callback){
    	if (!value) {
        	return callback();
      	}
    	setTimeout(() => {
        	var containSpecial = RegExp(/[(\ )(\~)(\!)(\@)(\#)(\$)(\%)(\^)(\&)(\*)(\()(\))(\-)(\_)(\+)(\=)(\[)(\])(\{)(\})(\|)(\\)(\;)(\:)(\')(\")(\,)(\.)(\/)(\<)(\>)(\?)(\)]+/); 
          	if (containSpecial.test(value)) {
				if(thisCurrentLanguage=='zh'){
					callback(new Error('内容不能含有特殊字符'));
				}else if(thisCurrentLanguage=='en'){
					callback(new Error('Content cannot contain special characters'));
				}else if(thisCurrentLanguage=='it'){
					callback(new Error('Il contenuto non può contenere caratteri speciali'));
				}  
            	
          	}else{
              	callback();
          	}
      	}, 200);
    },
    //密码校验
    validatePassword: function (rule,value,callback){
    	if (!value) {
        	return callback();
      	}
    	setTimeout(() => {
       		var regUrl = /^[a-zA-Z][a-zA-Z0-9_]*$/;
          	if (!regUrl.test(value)) {
				if(thisCurrentLanguage=='zh'){
					callback(new Error('以字母开头，长度在6-18之间，只能包含字母、数字和下划线'));
				}else if(thisCurrentLanguage=='en'){
					callback(new Error('Start with a letter and be between 6 and 18 in length. It can only contain letters, numbers and underscores.'));
				}else if(thisCurrentLanguage=='it'){
					callback(new Error('Inizia con una lettera e dai 6 ai 18 di lunghezza e può contenere solo lettere, numeri e caratteri di sottolineatura.'));
				}    
           	 	
          	}else{
              	callback();
          	}
      	}, 200);
    },
    //邮箱校验
    validateEmail: function (rule,value,callback){
    	if (!value) {
        	return callback();
      	}
    	setTimeout(() => {
        	var regUrl = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/ ;
          	if (!regUrl.test(value)) {
				if(thisCurrentLanguage=='zh'){
					callback(new Error('请输入正确格式的邮箱号码'));
				}else if(thisCurrentLanguage=='en'){
					callback(new Error('Please enter the correct format of the mailbox number'));
				}else if(thisCurrentLanguage=='it'){
					callback(new Error('Si prega di inserire il formato corretto del numero di casella postale'));
				}      
            	
          	}else{
              	callback();
         	}
      	}, 200);
    },
    //身份证校验
    validateIdCard: function (rule,value,callback){
    	if (!value) {
        	return callback();
      	}
    	setTimeout(() => {
        	var regUrl = /^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/ ;
          	if (!regUrl.test(value)) {
				if(thisCurrentLanguage=='zh'){
					callback(new Error('请输入正确格式的身份证号码'));
				}else if(thisCurrentLanguage=='en'){
					callback(new Error('Please enter the correct format ID number'));
				}else if(thisCurrentLanguage=='it'){
					callback(new Error('Si prega di inserire il numero ID di formato corretto'));
				}      
            	
          	}else{
              	callback();
          	}
      	}, 200);
    },
    //大于0小于1的小数
    validateDecimal: function (rule,value,callback){
    	if (!value) {
        	return callback();
      	}
    	setTimeout(() => {
        	var regUrl= /^0\.[1-9]\d*$/;
          	if (!regUrl.test(value)) {
				if(thisCurrentLanguage=='zh'){
					callback(new Error('请输入0到1的小数'));
				}else if(thisCurrentLanguage=='en'){
					callback(new Error('Please enter a decimal from 0 to 1.'));
				}else if(thisCurrentLanguage=='it'){
					callback(new Error('Si prega di inserire un decimale da 0 a 1.'));
				}        
            	
          	}else{
              	callback();
          	}
      	}, 200);
    },
    //百分比校验
    validatePercentage: function (rule,value,callback){
    	if (!value) {
            return callback();
        }
    	setTimeout(() => {
            var regUrl = /^(100|[1-9]?\d(\.\d\d?)?)%$/;
            if (!regUrl.test(value)) {
				if(thisCurrentLanguage=='zh'){
					callback(new Error('请输入正确的百分比格式'));
				}else if(thisCurrentLanguage=='en'){
					callback(new Error('Please enter the correct percentage format'));
				}else if(thisCurrentLanguage=='it'){
					callback(new Error('Si prega di inserire il formato percentuale corretto'));
				} 
                
            }else{
                callback();
            }
        }, 200);
    },
    //价格校验
    validatePrice: function (rule,value,callback){
    	if(!value){
			if(thisCurrentLanguage=='zh'){
				callback(new Error('不能为空'));
			}else if(thisCurrentLanguage=='en'){
				callback(new Error('Can not be empty'));
			}else if(thisCurrentLanguage=='it'){
				callback(new Error('Non può essere vuoto'));
			} 
  			
  		}
      	setTimeout(() => {
  			var  regUrl = /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/;
  			if(!regUrl.test(value)){
				if(thisCurrentLanguage=='zh'){
					callback(new Error('请输入正确格式的价格(x.xx;x.x;x)'));
				}else if(thisCurrentLanguage=='en'){
					callback(new Error('Please enter the price in the correct format (x.xx;x.x;x)'));
				}else if(thisCurrentLanguage=='it'){
					callback(new Error('Inserisci il prezzo nel formato corretto (x.xx; x.x; x)'));
				}   
  				
  			}else{
  				callback();
  			}
  		},100);
    },
    //价格校验（可为空）
    validateNullPrice: function (rule,value,callback){
      if(!value){
      return callback();
      };
        setTimeout(() => {
        var  regUrl = /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/;
        if(!regUrl.test(value)){
			if(thisCurrentLanguage=='zh'){
				callback(new Error('请输入正确格式的价格(x.xx;x.x;x)'));
			}else if(thisCurrentLanguage=='en'){
				callback(new Error('Please enter the price in the correct format (x.xx;x.x;x)'));
			}else if(thisCurrentLanguage=='it'){
				callback(new Error('Inserisci il prezzo nel formato corretto (x.xx; x.x; x)'));
			}   
        }else{
          callback();
        }
      },100);
    },
    //判断是否全部为空格
    validateTrim: function (rule,value,callback){
      if(!value){
		if(thisCurrentLanguage=='zh'){
			callback(new Error('不能为空'));
		}else if(thisCurrentLanguage=='en'){
			callback(new Error('Can not be empty'));
		}else if(thisCurrentLanguage=='it'){
			callback(new Error('Non può essere vuoto'));
		} 
      }
      setTimeout(() => {
        if (value.trim().length === 0) {
			if(thisCurrentLanguage=='zh'){
				callback(new Error('不能全部为空格'));
			}else if(thisCurrentLanguage=='en'){
				callback(new Error('Cannot be all spaces'));
			}else if(thisCurrentLanguage=='it'){
				callback(new Error('Non possono essere tutti gli spazi'));
			} 
         
        } else {
            callback();
        }
      },100);
    }
};
